﻿# This is executed last among all history
GLOBAL = {
	
	every_country = {
		limit = { NOT = { has_law = law_type:law_slavery_banned } }
		ig:ig_landowners = { add_ideology = ideology_pro_slavery }
	}
	
###ACHIEVEMENT VARIABLES###
	
	#Serf's Up
	every_country = {
	   limit = { has_law = law_type:law_serfdom }
	   set_variable = serfs_up_ach_possible
	}
	
	#The Berlin Conference
	every_country = {
		limit = {
			exists = c:PRU
			this = c:PRU
		}
		set_variable = the_berlin_conference_ach_possible
	}

	#Muhammad Ali's Ambition
	every_country = {
		limit = {
			exists = c:EGY
			this = c:EGY
		}
		set_variable = muhammed_alis_ambition_ach_possible
	}
	
	#Broken Promises
	every_country = {
		limit = {
			can_form_nation = ITA
		}
		set_variable = broken_promises_ach_possible
	}
	
	#Reading Campaign
	every_country = {
		limit = {
			literacy_rate <= 0.2
		}
		set_variable = reading_campaign_ach_possible
	}
	
	#We Are Not Amused
	every_country = {
		limit = {
			exists = c:GBR
			this = c:GBR
		}
		set_variable = we_are_not_amused_ach_possible
	}
	
	#Star Swarmed Banner
	every_country = {
		limit = {
			exists = c:USA
			this = c:USA
		}
		set_variable = star_swarmed_banner_ach_possible
	}
	
	#Peccavi
	every_country = {
		limit = {
			exists = c:BIC
			this = c:BIC
		}
		set_variable = peccavi_ach_possible
	}
	
	#Perkeletankki
	every_country = {
		limit = {
			exists = c:FIN
			this = c:FIN
		}
		set_variable = perkeletankki_ach_possible
	}
	
	#Luxurious Luxembourg
	every_country = {
		limit = {
			exists = c:LUX
			this = c:LUX
		}
		set_variable = luxurious_luxembourg_ach_possible
	}
	
	#Anarchy in the UK
	every_country = {
		limit = {
			exists = c:GBR
			this = c:GBR
		}
		set_variable = anarchy_in_the_uk_ach_possible
	}
	
	#An Empire Under the Pun
	every_country = {
		limit = {
			exists = c:PAN
			this = c:PAN
		}
		set_variable = an_empire_under_the_pun_ach_possible
	}
			
	#I Didn't Vote for Pedro
	every_country = {
		limit = {
			exists = c:BRZ
			this = c:BRZ
		}
		set_variable = i_didnt_vote_for_pedro_ach_possible
	}
	
	#Go West Young Man
	every_country = {
		limit = {
			exists = c:USA
			this = c:USA
		}
		set_variable = go_west_young_man_ach_possible
	}
	
	#The Western Protectorate
	every_country = {
		limit = {
			exists = c:CHI
			this = c:CHI
		}
		set_variable = the_western_protectorate_ach_possible
	}
	
	#The Paris Commune
	every_country = {
		limit = {
			exists = c:FRA
			this = c:FRA
		}
		set_variable = the_paris_commune_ach_possible
	}
	
	#Barbarys Back
	every_country = {
		limit = {
			exists = c:ALD
			this = c:ALD
		}
		set_variable = barbarys_back_ach_possible
	}
	
	#Miners and Minors
	every_country = {
		limit = {
			exists = c:LAN
			this = c:LAN
		}
		set_variable = miners_and_minors_ach_possible
	}
	
	#Healthy Man of Europe
	every_country = {
		limit = {
			exists = c:TUR
			this = c:TUR
		}
		set_variable = healthy_man_of_europe_ach_possible
	}
	
	#Habsburg Resurgence
	every_country = {
		limit = {
			exists = c:AUS
			this = c:AUS
		}
		set_variable = habsburg_resurgence_ach_possible
	}
	
	#The Great Game
	every_country = {
		limit = {
			exists = c:RUS
			this = c:RUS
		}
		set_variable = great_game_ach_possible
	}
	
	#Bourbon for Everyone
	every_country = {
		limit = {
			exists = c:SPA
			this = c:SPA
		}
		set_variable = bourbon_for_everyone_ach_possible
	}
	
	#American Territory
	every_country = {
		limit = {
			exists = c:SEQ
			this = c:SEQ
		}
		set_variable = american_territory_ach_possible
	}
	
	#Belle Epoque
	every_country = {
		limit = {
			exists = c:FRA
			this = c:FRA
		}
		set_variable = belle_epoque_ach_possible
	}
	
	#Risorgimento
	every_country = {
		limit = {
			can_form_nation = ITA
		}
		set_variable = risorgimento_ach_possible
	}
	
	#Three Hurrahs
	every_country = {
		limit = {
			can_form_nation = GER
		}
		set_variable = three_hurrahs_ach_possible
	}
	
	#Solomon's Quest
	every_country = {
		limit = {
			can_form_nation = ETH
		}
		set_variable = solomons_quest_ach_possible
	}
	
	#I Am a Scandinavian
	every_country = {
		limit = {
			can_form_nation = SCA
		}
		set_variable = i_am_a_scandinavian_ach_possible
	}

	#Grander Colombia
	every_country = {
		limit = {
			can_form_nation = GCO
		}
		set_variable = grander_colombia_ach_possible
	}

	#Manifest Mexico
	every_country = {
		limit = {
			this ?= c:MEX
		}
		set_variable = manifest_mexico_ach_possible
	}

	#Event Variables
	
	set_global_variable = {
		name = number_of_mega_earthquakes
		value = 0
	}

	set_global_variable = {
		name = number_of_mega_floods
		value = 0
	}
	
	set_global_variable = {
		name = number_of_mega_eruptions
		value = 0
	}
	
	s:STATE_DISTRICT_OF_COLUMBIA = {	
		set_variable = {
            name = usa_state_flag_block
            value = yes
        }

        set_variable = {
            name = district_of_columbia
            value = yes
        }
	}
	
	s:STATE_WEST_VIRGINIA = {	
        set_variable = {
            name = usa_state_flag_block
            value = yes
        }
	}

	c:UCA = {
		add_radicals = {
			value = 1.2
		}
	}

	c:BOL = {
		trigger_event = {
			id = peru_bolivia_confederation.1
		}
	}

	c:PEU = {
		trigger_event = {
			id = peru_bolivia_confederation.1
		}
	}

	c:RUS = {
		every_scope_state = {
            limit = {
                OR = {
                    state_region = s:STATE_KUBAN
                    state_region = s:STATE_DAGESTAN 
                }
            }
            add_radicals = {
                value = 1.5
                culture = cu:circassian
            }
			add_radicals = {
                value = very_large_radicals
            }
            add_radicals = {
                value = 0.75
                culture = cu:north_caucasian
            }
			add_radicals = {
                value = very_large_radicals
            }
        }
        create_truce = {
			country = c:CIR
			months = 60
		}
		create_truce = {
			country = c:CHC
			months = 60
		}
	}

	c:CHI = {
		random_scope_state = {
			limit = {	
				state_region = s:STATE_SICHUAN
			}
			add_radicals = {
                value = large_radicals
                culture = cu:han
            }
		}
		random_scope_state = {
			limit = {	
				state_region = s:STATE_YUNNAN
			}
			add_radicals = {
                value = small_radicals
                culture = cu:han
            }
		}
		random_scope_state = {
			limit = {	
				state_region = s:STATE_CHONGQING
			}
			add_radicals = {
                value = medium_radicals
                culture = cu:han
            }
		}
		add_radicals = {
			value = medium_radicals
			culture = cu:han
		}
	}

	c:HBC = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:NWT = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:COL = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:RAC = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:BIC = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	
	c:BPR = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	
	c:MPR = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:RGT = {
		add_to_variable_list = { name = past_overlord target = top_overlord }
	}

	c:URU = {
		trigger_event = {
			id = journal_flavor_uruguay.3
			days = 7
		}
	}
	
	#VFM GAME RULES HISTORY
	
	if = {
		limit = {
			has_game_rule = no_micro_european_nations
		}
		c:AUS = {
			annex = c:LIE
		}
		c:CAR = {
			annex = c:ANR
		}
	}
	
	if = {
		limit = {
			has_game_rule = vanilla_german_minors
		}
		c:MEI = {
			annex = c:GRZ
		}
		c:COB = {
			annex = c:GRA
			annex = c:ALN
		}
		c:SCW = {
			annex = c:SND
		}
		c:HOL = {
			annex = c:LAU
		}
		c:HOH = {
			annex = c:HHN
		}
	}

	if = {
		limit = {
			has_game_rule = no_confederations
		}
		c:BUE = {
			annex = c:COE
			annex = c:ENT
			annex = c:TUC
			annex = c:MDZ
			annex = c:SLT
			annex = c:SDE
			annex = c:SFE
			annex = c:CDA
			annex = c:JUJ
			annex = c:CMA
			annex = c:LRJ
			annex = c:SJN
			annex = c:SLS
			annex = c:MSS
			s:STATE_CHACO = {
				add_claim = c:BUE
			}
			s:STATE_SANTA_FE = {
				add_claim = c:BUE
			}
			s:STATE_RIO_NEGRO = {
				add_claim = c:BUE
			}
			change_tag = ARG
		}
		c:BEX = {
			annex = c:GVA
			annex = c:VAU
			annex = c:SRN
			annex = c:BSL
			annex = c:AAU
			annex = c:ZUR
			annex = c:SHU
			annex = c:THU
			annex = c:APA
			annex = c:GLL
			annex = c:GLA
			annex = c:GRS
			annex = c:TIC
			annex = c:NTL
			annex = c:API
			annex = c:VIS
			annex = c:FRI
			annex = c:URI
			annex = c:OBW
			annex = c:NID
			annex = c:LNE
			annex = c:ZUG
			annex = c:SCZ

			change_tag = SWI
		}

	}

	if = {
		limit = {
			has_game_rule = no_polish_subjects
		}
		c:RUS = {
			annex = c:CPL
		}
		c:PRU = {
			annex = c:POS
		}
	}

	if = {
		limit = {
			has_game_rule = congress_polish_subjects
		}
		c:RUS = {
			annex = c:CPL
		}
	}

	if = {
		limit = {
			has_game_rule = yes_polish_subjects
		}
		create_country = {
			tag = c:GAL
			origin = c:AUS
			state = s:STATE_WEST_GALICIA
			state = s:STATE_EAST_GALICIA
		}
	}

	if = {
		limit = {
			has_game_rule = no_caucasus_subjects
		}
		c:RUS = {
			annex = c:CAU
			annex = c:MIN
			annex = c:SVA
			annex = c:ABK
		}
	}

	if = {
		limit = {
			has_game_rule = no_baltic_subjects
		}
		c:RUS = {
			annex = c:EST
			annex = c:LVN
			annex = c:CRL
		}
	}
	
	#if = {
	#	limit = {
	#		has_game_rule = no_real_unions
	#	}
	#	every_country = {
	#		while = {
	#			limit = {
	#				any_subject_or_below = {
	#					count > 0
	#					is_subject_type = subject_type_real_union
	#				}
	#			}
	#			every_subject_or_below = {
	#				limit = {
	#					is_subject_type = subject_type_real_union
	#				}
	#				save_scope_as = real_union_subject
	#				overlord = {
	#					annex = scope:real_union_subject
	#				}
	#			}
	#		}
	#	}
	#}

	if = {
		limit = {
			has_game_rule = no_dependencies
		}
		every_country = {
			while = {
				limit = {
					any_subject_or_below = {
						count > 0
						is_subject_type = subject_type_dependency
					}
				}
				every_subject_or_below = {
					limit = {
						is_subject_type = subject_type_dependency
					}
					save_scope_as = dependency_subject
					overlord = {
						annex = scope:dependency_subject
					}
				}
			}
		}
	}

	if = {
		limit = {
			has_game_rule = no_NA_decentralized
		}
		c:USA = {
			annex = c:LKT
			annex = c:PWN
			annex = c:ARP
			annex = c:ABS
		}
		c:MEX = {
			annex = c:COM
			annex = c:UTE
			annex = c:NVJ
			annex = c:APC
		}
		c:COL = {
			annex = c:NZP
		}
		c:HBC = {
			annex = c:BLF
			annex = c:IRC
		}
	}

	every_state = {
		limit = {

			owner = {
				has_law = law_type:law_jizya
			}
			NOT = { has_modifier = jizya_state }

			any_scope_pop = {
				state = { save_temporary_scope_as = m_state }

				culture = { 
					has_homeland = scope:m_state
					#NOT = { is_primary_culture_of = root }
					NOT = { 
						#Check for muslim cultures to identify muslims,
						#until I can figure out how to find majority religions of cultures.
						OR = { 
							has_discrimination_trait = middle_eastern_heritage
							has_discrimination_trait = malay
							has_discrimination_trait = iranian_turanian_culture_group
							has_discrimination_trait = albanian_language
							has_discrimination_trait = arab_speaking
						}
					}
				}
				#These muslim cultures don't fit into any specific trait group and need to be pointed out specifically
				NOT = { 
					OR = {
					culture = cu:bosniak
					culture = cu:tatar
					culture = cu:fur
					culture = cu:swahili
					culture = cu:beja
					culture = cu:afar
					culture = cu:hausa
					culture = cu:fulbe
					culture = cu:dyula
					culture = cu:haratin
					culture = cu:mande
					culture = cu:maures
					culture = cu:songhai
					culture = cu:tuareg
					culture = cu:wolof
					}
				}

				religion = {
					NOT = { has_discrimination_trait = muslim }
				}
			}
		}
		add_modifier = {
			name = jizya_state
		}
	}

}
